package com.ycfmedical.bed.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.bilibili.magicasakura.widgets.TintButton;
import com.ycfmedical.bed.Constants;
import com.ycfmedical.bed.R;
import com.ycfmedical.bed.base.BaseMenuActivity;
import com.ycfmedical.bed.bean.BodySignParameterInfo;
import com.ycfmedical.bed.local.DataManager;
import com.ycfmedical.bed.model.VsModel;
import com.ycfmedical.bed.present.HomePresenter;
import com.ycfmedical.bed.serverdata.DBUtil;
import com.ycfmedical.bed.service.VitalSignService;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.droidlover.xdroidmvp.event.BusProvider;
import cn.droidlover.xdroidmvp.router.Router;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

import static com.ycfmedical.bed.utils.RefreshDataUtils.getRefreshDataUtils;

public class HomeActivity extends BaseMenuActivity<HomePresenter> {

    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;

    @BindView(R.id.btn_entertain)
    TintButton btnEntertain;

    @BindView(R.id.btn_health)
    TintButton btnHealth;

    @BindView(R.id.btn_clock)
    TintButton btnClock;

    @BindView(R.id.btn_his)
    TintButton btnHis;

    @BindView(R.id.btn_control)
    TintButton btnControl;

    @BindView(R.id.btn_nursestation)
    TintButton btnNursestation;

    @BindView(R.id.btn_personal)
    TintButton btnPersonal;

    @BindView(R.id.btn_equipment_temperature)
    TintButton btnTemperature;

    @BindView(R.id.btn_enjioin)
    TintButton btnEnjioin;

    @BindView(R.id.btn_voice)
    TintButton btnVoice;

    @BindView(R.id.btn_im)
    TintButton btnIm;

    @BindView(R.id.btn_equipment_weight)
    TintButton btnEquipmentWeight;

    @BindView(R.id.btn_vs)
    TintButton butvs;
    /**
     * 模拟数据传入
     */
    private boolean flag = true;
    private VsModel vsModel;
    DBUtil dbUtil = DBUtil.getInstance();

    public static void launch(Activity activity, int pagerValue) {
        Router.newIntent(activity).putInt(Constants.SHARE_HOMETAB_KEY, pagerValue).to(HomeActivity.class).launch();
    }

    // 隐藏toolbar回退键
    @Override
    protected boolean isShowBacking() {
        return false;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        // 从数据库读取用户数据保存在内存中
        getP().loadData();
        // 开启接收数据Service
        Intent intent = new Intent(HomeActivity.this, VitalSignService.class);
        startService(intent);
        vsModel = (VsModel) VsModel.getVsModel();
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_home;
    }

    @Override
    public HomePresenter newP() {
        return new HomePresenter();
    }

    @OnClick({R.id.btn_entertain, R.id.btn_health, R.id.btn_clock, R.id.btn_his, R.id.btn_control,
            R.id.btn_nursestation, R.id.btn_personal, R.id.btn_equipment_temperature, R.id.btn_equipment_weight, R.id.btn_enjioin, R.id.btn_voice,
            R.id.btn_im, R.id.btn_vs})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_entertain:
                EntertainActivity.launch(this);
                break;
            case R.id.btn_health:
                HealthNewActivity.launch(this);
                break;
            case R.id.btn_clock:
                TimingClockActivity.launch(this);
                break;
            case R.id.btn_his:
                // HisActivity.launch(this);
                MainActivity.launch(this, getIntent().getIntExtra(Constants.SHARE_HOMETAB_KEY, 0));
                break;
            case R.id.btn_control:
                ControlActivity.launch(this);
                break;
            case R.id.btn_nursestation:
                break;
            case R.id.btn_personal:
                //   UserinfoActivity.launch(this);
                MainActivity.launch(this, getIntent().getIntExtra(Constants.SHARE_HOMETAB_KEY, 0));
                break;
            case R.id.btn_equipment_temperature:
                TemperatureActivity.launch(this);
                break;
            case R.id.btn_equipment_weight:
                BodyWeightActivity.launch(this);
                break;
            case R.id.btn_enjioin:
                break;
            case R.id.btn_voice:
                this.finish();
                break;
            case R.id.btn_im:
                ImActivity.launch(this);
                break;
            case R.id.btn_vs:
                VitalSignActivity.launch(this);
        }
    }

//    @Override
//    public void onBackPressed()
//    {
//        Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
//        launcherIntent.addCategory(Intent.CATEGORY_HOME);
//        startActivity(launcherIntent);
//    }
}
